package com.lms.logisticsmanagementsystem.service.Impl;

import com.lms.logisticsmanagementsystem.mapper.CarMapper;
import com.lms.logisticsmanagementsystem.model.Car;
import com.lms.logisticsmanagementsystem.model.Driver;
import com.lms.logisticsmanagementsystem.model.Staff;
import com.lms.logisticsmanagementsystem.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CarServiceImpl implements CarService{
    @Autowired
    private CarMapper carMapper;
    @Override
    public List<Car> getCarInfo() {
        return carMapper.getCarInfo();
    }

    @Override
    public boolean addCarInfo(Car car) {
        Integer f = carMapper.addCarInfo(car);
        if (f==1){
            return true;
        }
        else return false;
    }

    @Override
    public Car getCarInfoById(Integer id) {
        Car car = carMapper.getCarInfoById(id);
        return car;
    }

    @Override
    public boolean delCarInfoById(Integer id) {
        Integer flag = carMapper.delCarInfoById(id);
        if (flag==1){
            return true;
        }else return false;
    }

    @Override
    public List<String> getCphmUnSelect() {
        //获取司机驾驶证车牌号码
        List<String> selectCphm = carMapper.getCphmSelect();
        List<String> allCphm = carMapper.getAllCphm();
        System.out.println(selectCphm);
        System.out.println(allCphm);
        List<String> unSelectCphm = new ArrayList<>();
        for (int i = 0; i < allCphm.size(); i++) {
            boolean flag = true;
            for (int j = 0; j < selectCphm.size(); j++) {
                if (selectCphm.get(j).equals(allCphm.get(i))){
                    flag=false;
                }
            }
            if (flag){
                unSelectCphm.add(allCphm.get(i));
            }
        }
        return unSelectCphm;
    }

    @Override
    public boolean addDriverInfo(Driver driver) {
        Integer flag = carMapper.addDriverInfo(driver);
        if (flag==1){
            return true;
        }else return false;
    }

    @Override
    public List<Driver> getDriverInfo() {
        List list  =carMapper.getDriverInfo();
        return list;
    }

    @Override
    public Driver getDriverInfoById(Integer id) {
        Driver driver = carMapper.editDriverInfoById(id);
        return driver;
    }

    @Override
    public boolean delDriverInfoById(Integer id) {
        Integer flag = carMapper.delDriverInfoById(id);
        if (flag==1){
            return true;
        }else return false;
    }

    @Override
    public List<String> getCarInfoByClassAndZT() {
        List<String> cars = carMapper.getCarInfoByClassAndZT();
        return cars;
    }

    @Override
    public List<Car> getCarBHByCLX(String clx) {
        List<Car> cars = carMapper.getCarBHByCLX(clx);
        return cars;
    }

    @Override
    public List<Driver> getDriverInfoByZT() {
        List<Driver> drivers = carMapper.getDriverInfoByZT();
        return drivers;
    }

    @Override
    public Car getCarInfoByCBH(String carCheck) {
        Car car = carMapper.getCarInfoByCBH(carCheck);
        return car;
    }

    @Override
    public boolean updateCarInfoByCBH(Car car) {
        Integer flag = carMapper.updateCarInfoByCBH(car);
        if (flag==1){
            return true;
        }else return false;
    }

    @Override
    public boolean updateDriverStatusById(Driver driver) {
        Integer flag = carMapper.updateDriverStatusById(driver);
        if (flag==1){
            return true;
        }else return false;
    }

    @Override
    public boolean updateCarStatusByCBH(String clbh) {
        Integer flag = carMapper.updateCarStatusByCBH(clbh);
        if (flag==1){
            return true;
        }else return false;
    }

    @Override
    public boolean updateDriverStatusByPhoneAndXM(String sjxm, String sjdh) {
        Integer flag = carMapper.updateDriverStatusByPhoneAndXM(sjxm,sjdh);
        if (flag==1){
            return true;
        }else return false;
    }

    @Override
    public boolean editDriverById(Driver driver) {
        Integer flag = carMapper.editDriverById(driver);
        if (flag==1){
            return true;
        }
        else return false;
    }

    @Override
    public boolean editCar(Car car) {
        Integer flag= carMapper.editCar(car);
        if (flag==1)
            return true;
        else return false;
    }

    @Override
    public List<Car> getCarInfoByCarNum(String carNum) {
        List<Car> list = carMapper.getCarInfoByCarNum(carNum);
        return list;
    }

    @Override
    public List<Driver> getDriverInfoByDriverTip(String drivertip) {
        List<Driver> list = carMapper.getDriverInfoByDriverTip(drivertip);
        return list;
    }
}
